package com.yx.frame.service;

public final class ActionManager {

	static ActionManager instance = null;

	static boolean isPerformanceMonitor = false;

	Action[] actionListArray = null;

	private ActionManager() {
	}

	public static ActionManager getInstace() {
		if (instance == null) {
			instance = new ActionManager();
		}
		return instance;
	}

	public void setActions(Action[] actionListArray) {
		if (actionListArray == null) {
			actionListArray = new Action[0];
		}
		this.actionListArray = actionListArray;
	}

	public static boolean isPerformanceMonitor() {
		return isPerformanceMonitor;
	}

	public static void setPerformanceMonitor(boolean monitor) {
		isPerformanceMonitor = monitor;
	}

	public int getActionsSize() {
		return actionListArray.length;
	}

	public Action[] listActions() {
		return actionListArray;
	}

	public Action getAction(int actionId, ServiceError error) throws Exception {
		if (actionId < 0 || actionId >= actionListArray.length) {
			error.setErrorMessage("没有找到操作对象，请求不合法");
			return null;
		}
		return actionListArray[actionId];
	}
}
